//
//  FaQiShenPiTableViewCell.m
//  JuBoCRM
//
//  Created by iMac on 2024/2/22.
//  Copyright © 2024 iningKe. All rights reserved.
//

#import "FaQiShenPiTableViewCell.h"
#import "FaQiShenPiCollectionViewCell.h"
@implementation FaQiShenPiTableViewCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
    
    _mainCollectionView.delegate = self;
    _mainCollectionView.dataSource = self;
    
    [_mainCollectionView registerNib:[UINib nibWithNibName:@"FaQiShenPiCollectionViewCell" bundle:nil] forCellWithReuseIdentifier:@"FaQiShenPiCollectionViewCell"];
    
}
- (void)setUserList:(NSArray *)userList{
    _userList = userList;
    [_mainCollectionView reloadData];
}

-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
    if(_userList.count > 3){
        return 4;
    }
    return _userList.count;
}
//创建cell
-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    FaQiShenPiCollectionViewCell * cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"FaQiShenPiCollectionViewCell" forIndexPath:indexPath];
    NSDictionary *dataDic = _userList[indexPath.row];
    if(_userList.count > 3){
        if(indexPath.row > 3){
            cell.itemImage.image = LocalImagePath(@"发起审批查看全部");
            cell.itemLabel.text = @"查看全部";
        }else{
            [cell.itemImage sd_setImageWithURL:WebImagePath(GetHandleString(dataDic, @"urlImage")) placeholderImage:HeadImagePlaceholder];
            cell.itemLabel.text = GetHandleString(dataDic, @"realname");
        }
    }else{
        [cell.itemImage sd_setImageWithURL:WebImagePath(GetHandleString(dataDic, @"urlImage")) placeholderImage:HeadImagePlaceholder];
        cell.itemLabel.text = GetHandleString(dataDic, @"realname");
    }

    return cell;
}





//设置item的大小
-(CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath{
    NSDictionary *dataDic = _userList[indexPath.row];
    NSDictionary *attrs = @{NSFontAttributeName : [UIFont boldSystemFontOfSize:13]};
    CGSize size=[GetHandleString(dataDic, @"realname") sizeWithAttributes:attrs];
    
    if(_userList.count > 3){
        if(indexPath.row > 3){
            return CGSizeMake(108, 44);
        }else{
            return CGSizeMake(53+size.width, 44);
        }
    }
    return CGSizeMake(53+size.width, 44);
}
//设置垂直间距,默认的垂直和水平间距都是10
-(CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout minimumLineSpacingForSectionAtIndex:(NSInteger)section
{
    return 0;
}
//设置水平间距
-(CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout minimumInteritemSpacingForSectionAtIndex:(NSInteger)section
{
    return 0;
}

//四周的边距
-(UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout insetForSectionAtIndex:(NSInteger)section
{
    return UIEdgeInsetsMake(0, 0, 0, 0);
}
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
    if(_manageClickBlock){
        _manageClickBlock(indexPath.row);
    }
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
